home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3035 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.2 KB

  1. Path: news.wasatch.com!news
  2. From: rdemanow@wasatch.com (Richard Demanowski)
  3. Newsgroups: comp.lang.c++,comp.lang.c
  4. Subject: getch() equivalency help ...
  5. Date: 20 Jan 1996 00:49:29 GMT
  6. Organization: wasatch.com
  7. Message-ID: <4dpe6p$e4j@twin.wasatch.com>
  8. NNTP-Posting-Host: port23.wasatch.com
  9.  
  10. I am looking for help with the following question/problem:
  11.  
  12. I want to have a function that does the same thing as getch() from
  13. conio.h, but without needing to include conio.h.
  14.  
  15. This is for a program that will be compiled across about 5 different 
  16. platforms, and the only one that supports conio.h is MS-DOS.
  17.  
  18. I know a similar function is available in UNIX with the ncurses library,
  19. but I don't have that on my UNIX box ...
  20.  
  21. I need a way to do what getch() does, i.e. pause and wait for a SINGLE
  22. KEYSTROKE and then pass the value of the pressed key back to the calling
  23. function.
  24.  
  25. For example:
  26.  
  27.     char incoming=getch();
  28.  
  29. will pause the program until a single key is pressed and feed the value of 
  30. that key to the char variable incoming.
  31.  
  32. I would most optimally like to be able to do this using only what's in 
  33. iostream.h or stdio.h, whose functions and operators behave alike across all 
  34. of my target platforms.
  35.  
  36. I have tried the following:
  37.  
  38.     char incoming=cin.get();
  39.  
  40. This pauses the program, but allows an entire line to be entered, terminated
  41. by a newline, and then only the first character of the line is fed to 
  42. incoming, and the rest of the line is available to the next input operation
  43. on the input stream.
  44.  
  45. The other version of cin.get() does the same thing:
  46.     
  47.     cin.get(incoming);
  48.  
  49. I have tried other functions from stdio.h that have the same result as above.
  50.  
  51.     char incoming=getchar();
  52.     char incoming=fgetc(stdin);
  53.  
  54. I can't seem to find a way to get just a single keystroke in and then flush
  55. the buffer ...
  56.  
  57. The only way I have been able to get the behaviour I want is with getch(), and
  58. it isn't supported on the other target platforms.
  59.  
  60. If anyone can help, I thank you in advance.
  61.  
  62. RichD
  63. rdemanow@wasatch.com
  64. rjd9404@wcslc.edu
  65.  
  66. -- 
  67. rdemanow@wasatch.com           |I am lost.  I have gone to look for
  68.                                |myself.
  69. press any key to continue ...  |If I should return before I get back,
  70. press any other key to quit ...|please ask me to wait here.
  71.  
  72.